//
//  SelectSort.swift
//  Sorts
//
//  Created by lhc on 2023/12/10.
//

import Foundation

class SelectSort: BaseSort {

    override func sort(action: ((OperatorType, (Int, Int)) -> ())) {
        for i in self.array.indices {
            var miniIndex = i
            for j in (i + 1)..<self.array.count {
                if self.array[j] < self.array[miniIndex] {
                    miniIndex = j
                }
            }
            
            if miniIndex != i {
                exchange(a: miniIndex, b: i)
                action(.exchange, (miniIndex, i))
            }
        }
    }
}
